import Vuex from "vuex";
import Vue from "vue";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    count: 0,
    zimu: "cuijian",
  },
  mutations: {
    ADDONE(state) {
      state.count++;
    },
    JIANONE(state) {
      state.count--;
    },
    YANCHE(state, value) {
      state.count += value;
    },
  },
  actions: {
    addone({ state, commit, dispatch }) {
      commit("ADDONE");
    },
    jianone({ state, commit, dispatch }) {
      commit("JIANONE");
    },
    addodd({ state, commit, dispatch }) {
      if (state.count % 2 !== 0) commit("ADDONE");
    },
    addeven({ state, commit, dispatch }) {
      if (state.count % 2 === 0) commit("ADDONE");
    },
    yanche({ state, commit, dispatch }, value) {
      setTimeout(() => {
        commit("YANCHE", value);
      }, 2000);
    },
  },
  getters: {
    me(state) {
      return state.zimu + "zhenshuai";
    },
  },
});
